const config = require('../configure')
const baseWebpackConfig = require('./base.config')
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
const { merge } = require('webpack-merge')

let mergeConfig = {}
if (config.isRenderer) {
  mergeConfig = {
    devServer: {
      port: config.devServerPort,
      headers: { 'Access-Control-Allow-Origin': '*' }
    },
    publicPath: config.rendererPublicPath
  }
}

const config1 = merge(baseWebpackConfig, {
  outputDir: config.clientOutpueDir,
  css: {
    // 是否要开启代码映射
    sourceMap: baseWebpackConfig.productionSourceMap,
  },
  configureWebpack: {
    entry: config.clientInputDir,
    // 客户端用web
    target: 'web',
    optimization: {
      // https://ssr.vuejs.org/zh/guide/build-config.html#%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%85%8D%E7%BD%AE-client-config
      runtimeChunk: {
        name: "manifest"
      }
    },
    plugins: [
      // 此插件在输出目录中
      // 生成 `vue-ssr-client-manifest.json`。
      new VueSSRClientPlugin({
        filename: config.clientManifestFileName
      })
    ]
  }
}, mergeConfig)

module.exports = config1